package com.erp.module.zhuanMaiDianTu

import android.content.Context
import android.util.Log
import com.erp.Interface.OnUserDataInterface
import com.erp.bean.PhotoBean
import com.erp.bean.zhuanmaidianTuBean
import com.erp.contacts.Contacts
import com.erp.contacts.Contacts.BOUNDARY
import com.erp.util.Httputil.*
import org.xutils.http.RequestParams
import org.xutils.x
import java.io.File

/**
 * Created by Administrator on 2019/3/20/020.
 * 作者：刘洋
 */
class ZhuanMaiDianTuModel {
    /**获取新开专卖店列表 */
    fun getZhuanMaiDian(context: Context, page: Int, pagesize: Int, code: Int, searchParams: String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.ZHUANMAIDIAN)
        getparams(context, params)
        params.addBodyParameter("page", page.toString())
        params.addBodyParameter("pagesize", pagesize.toString())
        if (code == 0) {
            params.addBodyParameter("searchParams[u_name_like]", searchParams)
        } else if (code == 1) {
            params.addBodyParameter("searchParams[alias_name]", searchParams)
        } else if (code == 2) {
            params.addBodyParameter("searchParams[esi_id_num]", searchParams)
        } else if (code == 3) {
            params.addBodyParameter("searchParams[area_name]", searchParams)
        } else if (code == 4) {
            params.addBodyParameter("searchParams[province]", searchParams)
        }

        x.http().get<String>(params, Call(context, onUserDataInterface))
    }
    /**获取专卖店数据 */
    fun zhuanMaiDian(context: Context?, id: String, onUserDataInterface: OnUserDataInterface?) {
        var params = RequestParams(Contacts.ZHUANMAIDIAN + id)
        getparams(context, params)
        setProsess(params)
//        params.addBodyParameter("x-oss-process-2", "image/resize,m_lfit,w_330,h_330", BOUNDARY)
        Log.d("getHttpClient",params.toString())
        x.http().get(params, Call(context, onUserDataInterface))
    }

    /**修改专卖店数据 */
    fun setZhuanMaiDian(context: Context, bean : zhuanmaidianTuBean, deletephoto : MutableList<PhotoBean>, onUserDataInterface: OnUserDataInterface){
        val params = RequestParams(Contacts.ZHUANMAIDIAN+bean.id+"/edit_anzhuang_attachment")
        getparams(context, params)
        addtoken(params)
        setProsess(params)
        params.addHeader("ACCEPT", "application/json")
        params.addBodyParameter("tel", bean.tel, BOUNDARY)
        params.addBodyParameter("provinc", bean.province, BOUNDARY)
        params.addBodyParameter("city", bean.city, BOUNDARY)
        params.addBodyParameter("county", bean.county, BOUNDARY)
        params.addBodyParameter("street", bean.street, BOUNDARY)
        params.addBodyParameter("addr", bean.addr, BOUNDARY)
        var addi = 0
        for(b in bean.listphoto){
            if(b.fid==""){
                params.addBodyParameter("files[new][$addi]", File(b.uri), BOUNDARY)
                addi++
            }
        }
        var deletei = 0
        for (b in deletephoto) {
            if (b.fid != "") {
                params.addBodyParameter("files[delete][" + b.fid + "]", b.fid, BOUNDARY)
            }
        }
        x.http().post<String>(params, Call(context, onUserDataInterface))
    }
}